<?

class ViewSettings	{

	function __construct()	{
	}
	
	function dashboard()	{
	
	
		return array( 'content'=> "<h1>Settings</h1>Live from the ViewSettings Class." );
	
	}
	
	function update( $params ) {
		global $DB;
		
		$key = explode( ".", $params->key );
		
		
		if ( count( $key ) > 1
		&& $Object = $DB->get_object( 'settings', "`key`='{$key[0]}'" )) {
			
			if( !$json = json_decode( $Object->get( "value" )))
				 $json = (object) array();
				 $json->{$key[1]} = $params->value;
			
			$Object->set( 'value', $json, true );
			
			return array( "message"=> "updated " . $key[0] );
		
		} else
		
			$DB->set( 'settings', array( 'key'=> $key[0], 'value'=> $params->value ));
	
			return array( "message"=> "created " . $key[0] );
		
		/*
		
		
		$key = array_shift( explode( ".", $tree = $this->vars->entry ));
		
		if( count( $tree ) &&  $Object = $DB->get( 'settings', "key='$key'" )) {
			
			$value = json_decode( $Object->get('value'));
			while( count( $tree ) > 1)
				$latter = $value->{array_unshift( $tree )};
				
				$latter->{$tree[0]}	= $this->vars->value;
				$value = json_encode( $latter);
		} else 	$value = $this->vars->value;
		

		$DB->set( 'settings', array( 'key'=> $key, 'value'=> $value ), array( 'key'=> $key ));*/

	}

}

?>